package org.openclinic.exception;

import java.util.ArrayList;
import java.util.List;

import org.springframework.validation.FieldError;
import org.springframework.validation.ObjectError;

public class DomainException extends RuntimeException {

	private static final long serialVersionUID = 8318492608344012043L;
	
	private List<ObjectError> errors;

	public DomainException(String objectName, String field, String code, String rejectedValue) {
		ObjectError objectError = new FieldError(objectName, field, rejectedValue, false, new String[] { code }, null, null);
		if (errors == null) {
			errors = new ArrayList<ObjectError>();
		}
		errors.add(objectError);
	}
	
	public DomainException(List<ObjectError> errors) {
		this.errors = errors;
	}
	
	public List<ObjectError> getErrors() {
		return errors;
	}
	
}
